window.onload=function()
{
    if($('#select option:selected').val()==2) {
        $("#invite").hide();
        $("#invite_num").val(1);
    }
    $("#goodsform").validate({
        rules: {
            name: {
                required: true,
                minlength: 2,
                maxlength:50
            },
            photo: "required",
            price: {
                required: true,
                number: true,
                min:0
            },
            invite_num: {
                required: "required",
                min: 1
            },
            stock: {
                required: "required",
                min: 0
            },
        },
        messages: {
            name: {
                required: "请输入用户名",
                minlength: "用户名必需由2个字符组成",
                maxlength: "用户名必需不大于50个字母组成"
            },
            photo: "请输入一个正确的邮箱",
            price: {
                required: "请输入价格",
                min: "兑换价格不能小于0",
                number: "兑换价格格式不正确",
            },
            invite_num: {
                required: "请输入邀请人数",
                min: "邀请人数不能小于1",
            },
            stock: {
                required: "请输入一个正确的库存",
                min: "库存必须大于0",
            },
            photo: "请上传一张图片",
        }
    });
};
function del(id, url, type='get') {
    layer.confirm("您确认要删除？", {
        title: '提示',
        btn: ['确认', '取消']
    }, function () {
        $.ajax({
            type: type,
            data:{'id':id},
            url: url,
            datatype:'json',
            success: function (data) {
                console.log(data);
                if(data.url){
                    layer.msg(data.info,function(){
                        window.location.href = data.url;
                    })
                } else {
                    layer.msg(data.info)
                }
            }
        });
    });
}
function upstatus(id,url,status) {
    layer.confirm("您确认要修改？", {
        title: '提示',
        btn: ['确认', '取消']
    }, function () {
        $.ajax({
            type: "get",
            data:{'id':id,"status":status},
            url: url,
            datatype:'json',
            success: function (data) {
                if(data.url){
                    layer.msg(data.info,function(){
                        window.location.href = data.url;
                    })
                } else {
                    layer.msg(data.info)
                }
            }
        });
    });
}